﻿using System;
using System.Windows;
using System.Windows.Controls;

namespace SLControlLibrary.Resources.Controls.Calendar.OutlookCalendar
{
    public class ucYearContent : ucItemsControl
    {
        #region Variables

        private ScrollViewer svContent = null;

        #endregion Variables

        #region Constructor

        public ucYearContent()
        {
            DefaultStyleKey = typeof(ucYearContent);
            this.Loaded += new RoutedEventHandler(ucYearContent_Loaded);
        }

        #endregion Constructor

        #region Methods

        void ucYearContent_Loaded(object sender, RoutedEventArgs e)
        {
            ScrollToCurrentTime();
        }

        public void ScrollToCurrentTime()
        {
            if (svContent == null) return;
            svContent.ScrollToVerticalOffset(svContent.ExtentHeight / 12 * (DateTime.Now.Month - 1));
        }

        #region OnApplyTemplate

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            svContent = (ScrollViewer)base.GetTemplateChild("svContent");

            if (svContent == null) return;

            ScrollViewerExtensions.SetIsMouseWheelScrollingEnabled(svContent, true);
        }

        #endregion OnApplyTemplate

        #endregion Methods
    }
}